<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .canvas{
            border: 1px solid red;
        }
    </style>
</head>
<body>
<canvas class="canvas" width="600px" height="400px">
    您的浏览器不支持
</canvas>
<script>
  var canvas = document.getElementsByClassName('canvas')[0]
  var ctx = canvas.getContext('2d')
  // canvas图形绘制
  ctx.fillRect(0,0,canvas.width,canvas.height)
  var img = new Image()
  img.src = 'img/logo.png'
    //一定要在图像加载完成后的回调中绘制图像
  img.onload = function () {
    //创建图形画刷，repeat,repeat-x,repeat-y,no-repeat
    var  pattern  = ctx.createPattern(img,'repeat')
    ctx.fillStyle = pattern
    ctx.fillRect(0,0,canvas.width,canvas.height)
  }



</script>
</body>
</html>
